package com.tsmti.core.common.convert;

import com.tsmti.core.util.DateUtils;
import org.springframework.util.StringUtils;

import java.beans.PropertyEditorSupport;

/**
 * @Package：com.tsmti.core.common.convert
 * @Class：DateConvertEditor
 * @Description： TODO
 * @Author：zcw
 * @Date：Created in 2018/4/20 14:41
 * @Company:
 * @Version：
 * @Modified By:
 */
public class DateConvertEditor extends PropertyEditorSupport {
    @Override
    public void setAsText(String text) throws IllegalArgumentException {
        if (StringUtils.hasText(text)) {
            try {
                setValue(DateUtils.parseDate(text));
            } catch (Exception ex) {
                IllegalArgumentException iae = new IllegalArgumentException("Could not parse date: " + ex.getMessage());
                iae.initCause(ex);
                throw iae;
            }
        } else {
            setValue(null);
        }
    }
}
